<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="vue.js"></script>
</head>
<body>
  <div id="app">
    <button @click="isShow = !isShow"> {{ isShow?"消失":"显示" }} </button>
    <keep-alive>
      <aa v-if="isShow"></aa>
    </keep-alive>
     
  
  </div>
  <script>
    let Aa = {
      template:`
        <div>
          <input v-model="msg"/>
        </div>
      `,
      data(){
        return {
          msg:""
        }
      },
      mounted () {
        console.log("mounted调用了");
      },
      beforeDestroy () {
        console.log("销毁之前");
      }
    }
    Vue.component("Aa",Aa)
    new Vue({
      el:"#app",
      data:{
        isShow:true
      }
    })
  </script>
</body>
</html>